import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { FC, PropsWithChildren, useState } from 'react';

import { RQProviderProps } from './RQProvider.props';

/**
 * Обертка для React Query. Необходимо обернуть ею все наше приложение
 * в файле main.tsx.
 *
 * @param children
 * @constructor
 */
const RQProvider: FC<PropsWithChildren<RQProviderProps>> = ({ children }) => {
  const [client] = useState(
    new QueryClient({
      defaultOptions: {
        queries: {
          refetchOnWindowFocus: false,
        },
      },
    }),
  );

  return <QueryClientProvider client={client}>{children}</QueryClientProvider>;
};

export default RQProvider;
